package com.chensheng.dao;

import com.chensheng.dto.OrderDTO;
import com.chensheng.model.OrderMaster;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Author:ChenSheng
 * @Description:
 * @Date: Created in 下午 16:46 2018/5/15 0015
 */
@Mapper
public interface OrderMasterDAO {

    @Insert({"insert order_master values " +
            "(#{orderId}, #{buyerName}, #{buyerPhone}, #{buyerAddress}, #{buyerOpenid}, " +
            "#{orderAmount}, #{orderStatus}, #{payStatus}, #{createTime}, #{updateTime})"})
    void insertOne(OrderMaster orderMaster);

    @Select({"select * from order_master where buyer_openid = #{openid} limit #{start},#{offset}"})
    List<OrderMaster> selectOneByOpenid(@Param("openid") String openid,
                                        @Param("start") Integer start,
                                        @Param("offset") Integer offset);

    @Select({"select * from order_master where order_id = #{orderId}"})
    OrderMaster selectOneByOrderId(@Param("orderId") String orderId);

    @Update({"update order_master set order_status = #{orderStatus} where order_id=#{orderId}"})
    void updateOrderStatus(@Param("orderStatus") Integer orderStatus, @Param("orderId") String orderId);

    @Update({"update order_master set pay_status = #{payStatus} where order_id=#{orderId}"})
    void updatePayStatus(@Param("payStatus") Integer payStatus,  @Param("orderId") String orderId);

    @Select({"select * from order_master limit #{start},#{offset}"})
    List<OrderMaster> selectAll(@Param("start") Integer start,
                                @Param("offset") Integer offset);

    @Select({"select count(order_id) from order_master"})
    Integer countAll();

}
